#include "os.h"
#include "compress.h"

#define  UNP_VER        20


enum { CRC16=1,CRC32=2 }; 
enum { OLD_DECODE=0,OLD_ENCODE=1,NEW_CRYPT=2 };

#define  LHD_PASSWORD       4
#define  LHD_SOLID          16

#define  SKIP_IF_UNKNOWN    0x4000
#define  LONG_BLOCK         0x8000

#define READSUBBLOCK	0x8000

enum { ALL_HEAD=0,MARK_HEAD=0x72,MAIN_HEAD=0x73,FILE_HEAD=0x74,
       COMM_HEAD=0x75,AV_HEAD=0x76,SUB_HEAD=0x77,PROTECT_HEAD=0x78};

enum { EA_HEAD=0x100 };


#pragma pack( push )
#pragma pack( 1 )

struct NewFileHeader
{
  UWORD HeadCRC;
  UBYTE HeadType;
  UWORD Flags;
  UWORD HeadSize;
  UDWORD PackSize;
  UDWORD UnpSize;
  UBYTE HostOS;
  UDWORD FileCRC;
  UDWORD FileTime;
  UBYTE UnpVer;
  UBYTE Method;
  UWORD NameSize;
  UDWORD FileAttr;
};

#pragma pack( pop )

unsigned int UnpRead(unsigned char *Addr,unsigned int Count);
unsigned int UnpWrite(unsigned char *Addr,unsigned int Count);
void Unpack(unsigned char *UnpAddr,int Solid);

void SetCryptKeys(char *Password);
void EncryptBlock(unsigned char *Buf);
void DecryptBlock(unsigned char *Buf);
void Crypt(UBYTE *Data,UDWORD Count,int Method);
void InitCRC(void);
UDWORD CRC(UDWORD StartCRC,void *Addr,UDWORD Size, int Mode);

